/*
 * Created by 岱青海蓝信息系统(北京)有限公司 on 17-5-19 下午2:15
 * Copyright (c) 2017. All rights reserved.
 */

package com.example.dqhl.recycleviewdemo.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.view.animation.RotateAnimation;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.dqhl.recycleviewdemo.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * description:   动画
 * autour:guanluocang
 * date:17/5/24 16:04
 */
public class AnimationActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tv_alpha;
    private TextView tv_scale;
    private TextView tv_translate;
    private TextView tv_rotate;
    private TextView tv_layout;
    private ImageView iv_pic;
    private Animation animation;
    private ListView listview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation);
        (iv_pic) = (ImageView) findViewById(R.id.iv_pic);
        (tv_alpha) = (TextView) findViewById(R.id.tv_alpha);
        tv_alpha.setOnClickListener(this);
        (tv_scale) = (TextView) findViewById(R.id.tv_scale);
        tv_scale.setOnClickListener(this);
        (tv_translate) = (TextView) findViewById(R.id.tv_translate);
        tv_translate.setOnClickListener(this);
        (tv_rotate) = (TextView) findViewById(R.id.tv_rotate);
        tv_rotate.setOnClickListener(this);
        (tv_layout) = (TextView) findViewById(R.id.tv_layout);
        tv_layout.setOnClickListener(this);
        (listview) = (ListView) findViewById(R.id.listview);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //从有到无
            case R.id.tv_alpha:
                animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
                iv_pic.startAnimation(animation);
                break;
            //缩放
            case R.id.tv_scale:
                animation = AnimationUtils.loadAnimation(this, R.anim.scale);
                iv_pic.startAnimation(animation);
                break;
            //位移
            case R.id.tv_translate:
                animation = AnimationUtils.loadAnimation(this, R.anim.translate);
                iv_pic.startAnimation(animation);
                break;
            //旋转
            case R.id.tv_rotate:
                RotateAnimation rotate;
                rotate = new RotateAnimation(0f, -180f, Animation.RELATIVE_TO_SELF,
                        0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                rotate.setDuration(1000);
                rotate.setFillAfter(true);
                iv_pic.startAnimation(rotate);
//                animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
//                iv_pic.startAnimation(animation);
                break;
            case R.id.tv_layout:
                List<String> stringList = new ArrayList<String>();
                for (int i = 0; i < 20; i++) {
                    stringList.add("啊哈哈哈" + i);
                }
                ArrayAdapter<String> stringAdatper = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, stringList);
                listview.setAdapter(stringAdatper);
                LayoutAnimationController lac = new LayoutAnimationController(AnimationUtils.loadAnimation(this, R.anim.zoom_in));
                lac.setOrder(LayoutAnimationController.ORDER_NORMAL);
                listview.setLayoutAnimation(lac);
                listview.startLayoutAnimation();

                break;
        }
    }
}
